{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Time series explorer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tstools.tstools as tsclass\n",
    "import ipywidgets\n",
    "from ipywidgets import HBox, VBox, Box, HTML\n",
    "import ee\n",
    "import warnings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f184ec00ee4d49919f567ce1e88cff4f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HTML(value='<style>.container { width:100% !important; }</style>')"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Allow Jupyter display to be 100% the width of the browser\n",
    "display(ipywidgets.HTML('<style>.container { width:100% !important; }</style>'))\n",
    "# Disable pandas and ccd warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Authenticate to the Earth Engine servers, and initialize the ee module.\n",
    "ee.Initialize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get a measures object\n",
    "tst = tsclass.TSTools()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Organize all widgets\n",
    "\n",
    "im_st = HTML(value=\"<b>IMAGE STRETCH:</b>\")\n",
    "\n",
    "stretch_tab = VBox([im_st, tst.image_band_1, tst.image_band_2, \n",
    "                    tst.image_band_3, tst.stretch_min,\n",
    "                    tst.stretch_max, tst.color_check,\n",
    "                    tst.clear_layers, tst.pyccd_button2, \n",
    "                    tst.toggle_pyccd_button2])\n",
    "display_tab = VBox([HTML(value=\"<b>CLICKED TS</b>\"), \n",
    "                    tst.band_selector2, tst.ylim2, tst.xlim2])\n",
    "\n",
    "panel = HBox([stretch_tab, display_tab], layout=ipywidgets.Layout(width='40%', min_height='400px', max_height='400px'))\n",
    "\n",
    "# Time series plots\n",
    "fig = ipywidgets.Tab(children=[tst.fig2, tst.fig3])\n",
    "fig.set_title(0, 'Clicked TS')\n",
    "fig.set_title(1, 'Clicked DOY')\n",
    "\n",
    "# Put the boxes together\n",
    "controls = HBox([tst.m, panel])\n",
    "\n",
    "# Put the boxes with the time series\n",
    "tabfig = VBox([controls, fig])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f0cdd6b86f3546839cbea5ac639f487e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(HBox(children=(Map(basemap={'url': 'http://server.arcgisonline.com/ArcGIS/rest/services/World_S…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(tabfig)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#### View input dataframe\n",
    "#tst.click_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#### View pyccd coefficients\n",
    "#tst.results['change_models']"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
